/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package org.quality4spl.fm.cvm.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList;
import org.eclipse.emf.ecore.util.InternalEList;

import org.quality4spl.fm.cvm.CvmPackage;
import org.quality4spl.fm.cvm.NamedElement;
import org.quality4spl.fm.cvm.UserAttributeType;
import org.quality4spl.fm.cvm.UserAttributeTypeContext;
import org.quality4spl.fm.cvm.VariabilityModel;
import org.quality4spl.fm.cvm.VariabilityModelEntry;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Variability Model</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.quality4spl.fm.cvm.impl.VariabilityModelImpl#getName <em>Name</em>}</li>
 *   <li>{@link org.quality4spl.fm.cvm.impl.VariabilityModelImpl#getDescription <em>Description</em>}</li>
 *   <li>{@link org.quality4spl.fm.cvm.impl.VariabilityModelImpl#getUserAttributeTypes <em>User Attribute Types</em>}</li>
 *   <li>{@link org.quality4spl.fm.cvm.impl.VariabilityModelImpl#getRootEntries <em>Root Entries</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class VariabilityModelImpl extends VariabilityModelElementImpl implements VariabilityModel {
	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * The default value of the '{@link #getDescription() <em>Description</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDescription()
	 * @generated
	 * @ordered
	 */
	protected static final String DESCRIPTION_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getDescription() <em>Description</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDescription()
	 * @generated
	 * @ordered
	 */
	protected String description = DESCRIPTION_EDEFAULT;

	/**
	 * The cached value of the '{@link #getUserAttributeTypes() <em>User Attribute Types</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getUserAttributeTypes()
	 * @generated
	 * @ordered
	 */
	protected EList<UserAttributeType> userAttributeTypes;

	/**
	 * The cached value of the '{@link #getRootEntries() <em>Root Entries</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getRootEntries()
	 * @generated
	 * @ordered
	 */
	protected EList<VariabilityModelEntry> rootEntries;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected VariabilityModelImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return CvmPackage.Literals.VARIABILITY_MODEL;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, CvmPackage.VARIABILITY_MODEL__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setDescription(String newDescription) {
		String oldDescription = description;
		description = newDescription;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, CvmPackage.VARIABILITY_MODEL__DESCRIPTION, oldDescription, description));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<UserAttributeType> getUserAttributeTypes() {
		if (userAttributeTypes == null) {
			userAttributeTypes = new EObjectContainmentWithInverseEList<UserAttributeType>(UserAttributeType.class, this, CvmPackage.VARIABILITY_MODEL__USER_ATTRIBUTE_TYPES, CvmPackage.USER_ATTRIBUTE_TYPE__CONTEXT);
		}
		return userAttributeTypes;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<VariabilityModelEntry> getRootEntries() {
		if (rootEntries == null) {
			rootEntries = new EObjectContainmentWithInverseEList<VariabilityModelEntry>(VariabilityModelEntry.class, this, CvmPackage.VARIABILITY_MODEL__ROOT_ENTRIES, CvmPackage.VARIABILITY_MODEL_ENTRY__PARENT_MODEL);
		}
		return rootEntries;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case CvmPackage.VARIABILITY_MODEL__USER_ATTRIBUTE_TYPES:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getUserAttributeTypes()).basicAdd(otherEnd, msgs);
			case CvmPackage.VARIABILITY_MODEL__ROOT_ENTRIES:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getRootEntries()).basicAdd(otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case CvmPackage.VARIABILITY_MODEL__USER_ATTRIBUTE_TYPES:
				return ((InternalEList<?>)getUserAttributeTypes()).basicRemove(otherEnd, msgs);
			case CvmPackage.VARIABILITY_MODEL__ROOT_ENTRIES:
				return ((InternalEList<?>)getRootEntries()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case CvmPackage.VARIABILITY_MODEL__NAME:
				return getName();
			case CvmPackage.VARIABILITY_MODEL__DESCRIPTION:
				return getDescription();
			case CvmPackage.VARIABILITY_MODEL__USER_ATTRIBUTE_TYPES:
				return getUserAttributeTypes();
			case CvmPackage.VARIABILITY_MODEL__ROOT_ENTRIES:
				return getRootEntries();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case CvmPackage.VARIABILITY_MODEL__NAME:
				setName((String)newValue);
				return;
			case CvmPackage.VARIABILITY_MODEL__DESCRIPTION:
				setDescription((String)newValue);
				return;
			case CvmPackage.VARIABILITY_MODEL__USER_ATTRIBUTE_TYPES:
				getUserAttributeTypes().clear();
				getUserAttributeTypes().addAll((Collection<? extends UserAttributeType>)newValue);
				return;
			case CvmPackage.VARIABILITY_MODEL__ROOT_ENTRIES:
				getRootEntries().clear();
				getRootEntries().addAll((Collection<? extends VariabilityModelEntry>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case CvmPackage.VARIABILITY_MODEL__NAME:
				setName(NAME_EDEFAULT);
				return;
			case CvmPackage.VARIABILITY_MODEL__DESCRIPTION:
				setDescription(DESCRIPTION_EDEFAULT);
				return;
			case CvmPackage.VARIABILITY_MODEL__USER_ATTRIBUTE_TYPES:
				getUserAttributeTypes().clear();
				return;
			case CvmPackage.VARIABILITY_MODEL__ROOT_ENTRIES:
				getRootEntries().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case CvmPackage.VARIABILITY_MODEL__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case CvmPackage.VARIABILITY_MODEL__DESCRIPTION:
				return DESCRIPTION_EDEFAULT == null ? description != null : !DESCRIPTION_EDEFAULT.equals(description);
			case CvmPackage.VARIABILITY_MODEL__USER_ATTRIBUTE_TYPES:
				return userAttributeTypes != null && !userAttributeTypes.isEmpty();
			case CvmPackage.VARIABILITY_MODEL__ROOT_ENTRIES:
				return rootEntries != null && !rootEntries.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public int eBaseStructuralFeatureID(int derivedFeatureID, Class<?> baseClass) {
		if (baseClass == NamedElement.class) {
			switch (derivedFeatureID) {
				case CvmPackage.VARIABILITY_MODEL__NAME: return CvmPackage.NAMED_ELEMENT__NAME;
				case CvmPackage.VARIABILITY_MODEL__DESCRIPTION: return CvmPackage.NAMED_ELEMENT__DESCRIPTION;
				default: return -1;
			}
		}
		if (baseClass == UserAttributeTypeContext.class) {
			switch (derivedFeatureID) {
				case CvmPackage.VARIABILITY_MODEL__USER_ATTRIBUTE_TYPES: return CvmPackage.USER_ATTRIBUTE_TYPE_CONTEXT__USER_ATTRIBUTE_TYPES;
				default: return -1;
			}
		}
		return super.eBaseStructuralFeatureID(derivedFeatureID, baseClass);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public int eDerivedStructuralFeatureID(int baseFeatureID, Class<?> baseClass) {
		if (baseClass == NamedElement.class) {
			switch (baseFeatureID) {
				case CvmPackage.NAMED_ELEMENT__NAME: return CvmPackage.VARIABILITY_MODEL__NAME;
				case CvmPackage.NAMED_ELEMENT__DESCRIPTION: return CvmPackage.VARIABILITY_MODEL__DESCRIPTION;
				default: return -1;
			}
		}
		if (baseClass == UserAttributeTypeContext.class) {
			switch (baseFeatureID) {
				case CvmPackage.USER_ATTRIBUTE_TYPE_CONTEXT__USER_ATTRIBUTE_TYPES: return CvmPackage.VARIABILITY_MODEL__USER_ATTRIBUTE_TYPES;
				default: return -1;
			}
		}
		return super.eDerivedStructuralFeatureID(baseFeatureID, baseClass);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (name: ");
		result.append(name);
		result.append(", description: ");
		result.append(description);
		result.append(')');
		return result.toString();
	}

} //VariabilityModelImpl
